<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8">
    
    <title>numpy.poly1d &mdash; NumPy v1.18 Manual</title>
    
    <link rel="stylesheet" type="text/css" href="../../_static/css/spc-bootstrap.css">
    <link rel="stylesheet" type="text/css" href="../../_static/css/spc-extend.css">
    <link rel="stylesheet" href="../../_static/scipy.css" type="text/css" >
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" >
    <link rel="stylesheet" href="../../_static/graphviz.css" type="text/css" >
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '1.18.1',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  false
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <script type="text/javascript" src="../../_static/language_data.js"></script>
    <script type="text/javascript" src="../../_static/js/copybutton.js"></script>
    <link rel="author" title="About these documents" href="../../about.html" >
    <link rel="index" title="Index" href="../../genindex.html" >
    <link rel="search" title="Search" href="../../search.html" >
    <link rel="top" title="NumPy v1.18 Manual" href="../../index.html" >
    <link rel="up" title="Poly1d" href="../routines.polynomials.poly1d.html" >
    <link rel="next" title="numpy.poly1d.__call__" href="numpy.poly1d.__call__.html" >
    <link rel="prev" title="Poly1d" href="../routines.polynomials.poly1d.html" > 
  </head>
  <body>
<div class="container">
  <div class="top-scipy-org-logo-header" style="background-color: #a2bae8;">
    <a href="../../index.html">
      <img border=0 alt="NumPy" src="../../_static/numpy_logo.png"></a>
    </div>
  </div>
</div>


    <div class="container">
      <div class="main">
        
	<div class="row-fluid">
	  <div class="span12">
	    <div class="spc-navbar">
              
    <ul class="nav nav-pills pull-left">
        <li class="active"><a href="https://numpy.org/">NumPy.org</a></li>
        <li class="active"><a href="https://numpy.org/doc">Docs</a></li>
        
        <li class="active"><a href="../../index.html">NumPy v1.18 Manual</a></li>
        

          <li class="active"><a href="../index.html" >NumPy Reference</a></li>
          <li class="active"><a href="../routines.html" >Routines</a></li>
          <li class="active"><a href="../routines.polynomials.html" >Polynomials</a></li>
          <li class="active"><a href="../routines.polynomials.poly1d.html" accesskey="U">Poly1d</a></li> 
    </ul>
              
              
    <ul class="nav nav-pills pull-right">
      <li class="active">
        <a href="../../genindex.html" title="General Index"
           accesskey="I">index</a>
      </li>
      <li class="active">
        <a href="numpy.poly1d.__call__.html" title="numpy.poly1d.__call__"
           accesskey="N">next</a>
      </li>
      <li class="active">
        <a href="../routines.polynomials.poly1d.html" title="Poly1d"
           accesskey="P">previous</a>
      </li>
    </ul>
              
	    </div>
	  </div>
	</div>
        

	<div class="row-fluid">
      <div class="spc-rightsidebar span3">
        <div class="sphinxsidebarwrapper">
  <h4>Previous topic</h4>
  <p class="topless"><a href="../routines.polynomials.poly1d.html"
                        title="previous chapter">Poly1d</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="numpy.poly1d.__call__.html"
                        title="next chapter">numpy.poly1d.__call__</a></p>
<div id="searchbox" style="display: none" role="search">
  <h4>Quick search</h4>
    <div>
    <form class="search" action="../../search.html" method="get">
      <input type="text" style="width: inherit;" name="q" />
      <input type="submit" value="search" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
          <div class="span9">
            
        <div class="bodywrapper">
          <div class="body" id="spc-section-body">
            
  <div class="section" id="numpy-poly1d">
<h1>numpy.poly1d<a class="headerlink" href="#numpy-poly1d" title="Permalink to this headline">¶</a></h1>
<dl class="class">
<dt id="numpy.poly1d">
<em class="property">class </em><code class="sig-prename descclassname">numpy.</code><code class="sig-name descname">poly1d</code><span class="sig-paren">(</span><em class="sig-param">c_or_r</em>, <em class="sig-param">r=False</em>, <em class="sig-param">variable=None</em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/numpy/numpy/blob/v1.18.1/numpy/__init__.py"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#numpy.poly1d" title="Permalink to this definition">¶</a></dt>
<dd><p>A one-dimensional polynomial class.</p>
<p>A convenience class, used to encapsulate “natural” operations on
polynomials so that said operations may take on their customary
form in code (see Examples).</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><dl class="simple">
<dt><strong>c_or_r</strong><span class="classifier">array_like</span></dt><dd><p>The polynomial’s coefficients, in decreasing powers, or if
the value of the second parameter is True, the polynomial’s
roots (values where the polynomial evaluates to 0).  For example,
<code class="docutils literal notranslate"><span class="pre">poly1d([1,</span> <span class="pre">2,</span> <span class="pre">3])</span></code> returns an object that represents
<img class="math" src="../../_images/math/b51ab88935f6aaf26ffb4e9ec86d639db9611c65.svg" alt="x^2 + 2x + 3"/>, whereas <code class="docutils literal notranslate"><span class="pre">poly1d([1,</span> <span class="pre">2,</span> <span class="pre">3],</span> <span class="pre">True)</span></code> returns
one that represents <img class="math" src="../../_images/math/3564d8771a390d726d1fec4c00bb839916c486c5.svg" alt="(x-1)(x-2)(x-3) = x^3 - 6x^2 + 11x -6"/>.</p>
</dd>
<dt><strong>r</strong><span class="classifier">bool, optional</span></dt><dd><p>If True, <em class="xref py py-obj">c_or_r</em> specifies the polynomial’s roots; the default
is False.</p>
</dd>
<dt><strong>variable</strong><span class="classifier">str, optional</span></dt><dd><p>Changes the variable used when printing <em class="xref py py-obj">p</em> from <em class="xref py py-obj">x</em> to <a class="reference internal" href="numpy.poly1d.variable.html#numpy.poly1d.variable" title="numpy.poly1d.variable"><code class="xref py py-obj docutils literal notranslate"><span class="pre">variable</span></code></a>
(see Examples).</p>
</dd>
</dl>
</dd>
</dl>
<p class="rubric">Examples</p>
<p>Construct the polynomial <img class="math" src="../../_images/math/b51ab88935f6aaf26ffb4e9ec86d639db9611c65.svg" alt="x^2 + 2x + 3"/>:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">poly1d</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">poly1d</span><span class="p">(</span><span class="n">p</span><span class="p">))</span>
<span class="go">   2</span>
<span class="go">1 x + 2 x + 3</span>
</pre></div>
</div>
<p>Evaluate the polynomial at <img class="math" src="../../_images/math/f61596f0289a4050418c8a2d2e9d9d65b2df83cf.svg" alt="x = 0.5"/>:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="p">(</span><span class="mf">0.5</span><span class="p">)</span>
<span class="go">4.25</span>
</pre></div>
</div>
<p>Find the roots:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">r</span>
<span class="go">array([-1.+1.41421356j, -1.-1.41421356j])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">r</span><span class="p">)</span>
<span class="go">array([ -4.44089210e-16+0.j,  -4.44089210e-16+0.j]) # may vary</span>
</pre></div>
</div>
<p>These numbers in the previous line represent (0, 0) to machine precision</p>
<p>Show the coefficients:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">c</span>
<span class="go">array([1, 2, 3])</span>
</pre></div>
</div>
<p>Display the order (the leading zero-coefficients are removed):</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">order</span>
<span class="go">2</span>
</pre></div>
</div>
<p>Show the coefficient of the k-th power in the polynomial
(which is equivalent to <code class="docutils literal notranslate"><span class="pre">p.c[-(i+1)]</span></code>):</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
<span class="go">2</span>
</pre></div>
</div>
<p>Polynomials can be added, subtracted, multiplied, and divided
(returns quotient and remainder):</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">*</span> <span class="n">p</span>
<span class="go">poly1d([ 1,  4, 10, 12,  9])</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">(</span><span class="n">p</span><span class="o">**</span><span class="mi">3</span> <span class="o">+</span> <span class="mi">4</span><span class="p">)</span> <span class="o">/</span> <span class="n">p</span>
<span class="go">(poly1d([ 1.,  4., 10., 12.,  9.]), poly1d([4.]))</span>
</pre></div>
</div>
<p><code class="docutils literal notranslate"><span class="pre">asarray(p)</span></code> gives the coefficient array, so polynomials can be
used in all functions that accept arrays:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">**</span><span class="mi">2</span> <span class="c1"># square of polynomial</span>
<span class="go">poly1d([ 1,  4, 10, 12,  9])</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">square</span><span class="p">(</span><span class="n">p</span><span class="p">)</span> <span class="c1"># square of individual coefficients</span>
<span class="go">array([1, 4, 9])</span>
</pre></div>
</div>
<p>The variable used in the string representation of <em class="xref py py-obj">p</em> can be modified,
using the <a class="reference internal" href="numpy.poly1d.variable.html#numpy.poly1d.variable" title="numpy.poly1d.variable"><code class="xref py py-obj docutils literal notranslate"><span class="pre">variable</span></code></a> parameter:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">poly1d</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">],</span> <span class="n">variable</span><span class="o">=</span><span class="s1">&#39;z&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>
<span class="go">   2</span>
<span class="go">1 z + 2 z + 3</span>
</pre></div>
</div>
<p>Construct a polynomial from its roots:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">poly1d</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="kc">True</span><span class="p">)</span>
<span class="go">poly1d([ 1., -3.,  2.])</span>
</pre></div>
</div>
<p>This is the same polynomial as obtained by:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">poly1d</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">])</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">poly1d</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="o">-</span><span class="mi">2</span><span class="p">])</span>
<span class="go">poly1d([ 1, -3,  2])</span>
</pre></div>
</div>
<dl class="field-list simple">
<dt class="field-odd">Attributes</dt>
<dd class="field-odd"><dl class="simple">
<dt><a class="reference internal" href="numpy.poly1d.c.html#numpy.poly1d.c" title="numpy.poly1d.c"><code class="xref py py-obj docutils literal notranslate"><span class="pre">c</span></code></a></dt><dd><p>The polynomial coefficients</p>
</dd>
<dt><a class="reference internal" href="numpy.poly1d.coef.html#numpy.poly1d.coef" title="numpy.poly1d.coef"><code class="xref py py-obj docutils literal notranslate"><span class="pre">coef</span></code></a></dt><dd><p>The polynomial coefficients</p>
</dd>
<dt><a class="reference internal" href="numpy.poly1d.coefficients.html#numpy.poly1d.coefficients" title="numpy.poly1d.coefficients"><code class="xref py py-obj docutils literal notranslate"><span class="pre">coefficients</span></code></a></dt><dd><p>The polynomial coefficients</p>
</dd>
<dt><a class="reference internal" href="numpy.poly1d.coeffs.html#numpy.poly1d.coeffs" title="numpy.poly1d.coeffs"><code class="xref py py-obj docutils literal notranslate"><span class="pre">coeffs</span></code></a></dt><dd><p>The polynomial coefficients</p>
</dd>
<dt><a class="reference internal" href="numpy.poly1d.o.html#numpy.poly1d.o" title="numpy.poly1d.o"><code class="xref py py-obj docutils literal notranslate"><span class="pre">o</span></code></a></dt><dd><p>The order or degree of the polynomial</p>
</dd>
<dt><a class="reference internal" href="numpy.poly1d.order.html#numpy.poly1d.order" title="numpy.poly1d.order"><code class="xref py py-obj docutils literal notranslate"><span class="pre">order</span></code></a></dt><dd><p>The order or degree of the polynomial</p>
</dd>
<dt><a class="reference internal" href="numpy.poly1d.r.html#numpy.poly1d.r" title="numpy.poly1d.r"><code class="xref py py-obj docutils literal notranslate"><span class="pre">r</span></code></a></dt><dd><p>The roots of the polynomial, where self(x) == 0</p>
</dd>
<dt><a class="reference internal" href="numpy.roots.html#numpy.roots" title="numpy.roots"><code class="xref py py-obj docutils literal notranslate"><span class="pre">roots</span></code></a></dt><dd><p>The roots of the polynomial, where self(x) == 0</p>
</dd>
<dt><a class="reference internal" href="numpy.poly1d.variable.html#numpy.poly1d.variable" title="numpy.poly1d.variable"><code class="xref py py-obj docutils literal notranslate"><span class="pre">variable</span></code></a></dt><dd><p>The name of the polynomial variable</p>
</dd>
</dl>
</dd>
</dl>
<p class="rubric">Methods</p>
<table class="longtable docutils align-default">
<colgroup>
<col style="width: 10%" />
<col style="width: 90%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="numpy.poly1d.__call__.html#numpy.poly1d.__call__" title="numpy.poly1d.__call__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">__call__</span></code></a>(self, val)</p></td>
<td><p>Call self as a function.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="numpy.poly1d.deriv.html#numpy.poly1d.deriv" title="numpy.poly1d.deriv"><code class="xref py py-obj docutils literal notranslate"><span class="pre">deriv</span></code></a>(self[, m])</p></td>
<td><p>Return a derivative of this polynomial.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="numpy.poly1d.integ.html#numpy.poly1d.integ" title="numpy.poly1d.integ"><code class="xref py py-obj docutils literal notranslate"><span class="pre">integ</span></code></a>(self[, m, k])</p></td>
<td><p>Return an antiderivative (indefinite integral) of this polynomial.</p></td>
</tr>
</tbody>
</table>
</dd></dl>

</div>


          </div>
        </div>
          </div>
        </div>
      </div>
    </div>

    <div class="container container-navbar-bottom">
      <div class="spc-navbar">
        
      </div>
    </div>
    <div class="container">
    <div class="footer">
    <div class="row-fluid">
    <ul class="inline pull-left">
      <li>
        &copy; Copyright 2008-2019, The SciPy community.
      </li>
      <li>
      Last updated on Feb 20, 2020.
      </li>
      <li>
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 2.4.2.
      </li>
    </ul>
    </div>
    </div>
    </div>
  </body>
</html>